package figure8.GUI;

import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JTextField;

import figure8.Controller;
import figure8.WAVTrack;

public class ChangeTrackNameWindow extends JDialog {

	public ChangeTrackNameWindow (final Controller controller, final WAVTrack track, final WAVTrackSettingsPanel panel) {
		super();

		this.setLocation(controller.getWindow().getFrame().getX() + 80, controller.getWindow().getFrame()
				.getY() + 120);
		
		final ChangeTrackNameWindow audioWin = this;

		this.getContentPane().setLayout(new GridLayout(2,1,5,5));
		this.setIconImage(Toolkit.getDefaultToolkit().getImage("src/figure8/GUI/Fig8-small.png"));
		this.setAlwaysOnTop(true);
		final JTextField enterName = new JTextField(track.getName());

		JButton submit = new JButton("Submit");
		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				track.setName(enterName.getText());
				panel.setLabel(track.getName());
				audioWin.dispose();
			}
		});
		this.getContentPane().add(enterName);
		this.getContentPane().add(submit);
		this.pack();
		this.setVisible(true);
	}
}